import { useTable, LIST_TYPE } from '@crud/index';
import { getColonelOrderList } from '@/api/crm-agency/dyj/colonel-order';
import { formatParamsSelectVal } from '@/utils';
import { useRoute } from 'vue-router';

// 查询

export const payOptions = [
  { label: '不限', value: -1 },
  { label: '会员代充', value: 1 },
  { label: '会员采购', value: 2 }
];
export const commissionStatusOptions = [
  { label: '不限', value: -1 },
  { label: '已结算', value: 1 },
  { label: '未结算', value: 0 }
];
export const typeOptions = [
  { label: '不限', value: -1 },
  { label: '老客户', value: 1 },
  { label: '新客户', value: 2 }
];
export const treeDataOptions = [
  { label: '不限', value: -1 },
  { label: '月卡VIP', value: 1 },
  { label: '年卡VIP', value: 2 },
  { label: '年卡SVIP', value: 3 }
];

export const isInvoiceMap: any = { 0: '未开票', 1: '未开票', 2: '已开票' };

// 表格
export const useTableList = (options: any = {}) => {
  const route = useRoute();

  const columns: any = [
    { label: '群峰订单ID', prop: 'trade_no', minWidth: 180, tooltip: true, fixed: 'left' },
    { label: '代理商名称', prop: 'colonel_name', minWidth: 160, tooltip: true },
    { label: '代理手机号', prop: 'colonel_mobile', minWidth: 120, tooltip: true },
    { label: '抖音昵称', prop: 'user_name', minWidth: 160, tooltip: true },
    { label: '大赢加主账号', prop: 'user_name', minWidth: 160, tooltip: true },
    { label: '大赢加手机号', prop: 'mobile', minWidth: 120, tooltip: true },
    { label: '客户类型', prop: 'is_new_order_str', width: 120 },
    { label: '支付金额', prop: 'total_fee', minWidth: 120 },
    { label: '佣金', prop: 'settle_fee', minWidth: 120, render: 'settle_fee', align: 'center' },
    { label: '是否开票', prop: 'is_invoice', minWidth: 120, render: (s: any) => isInvoiceMap[s.row.is_invoice] },
    { label: '付款时间', prop: 'add_time', minWidth: 177, type: 'dateTime' },
    { label: '备注', prop: 'remark', render: 'remark', width: 200, fixed: 'right', align: 'center' }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: '',
      from_dt: undefined,
      to_dt: undefined,
      colonel_id: -1,
      commission_status: -1,
      pay_type: -1,
      product: -1,
      team_count: -1,
      user_type: -1
    },
    columns: columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.from_dt = begin;
        params.to_dt = end;
      }

      params.colonel_id = route?.query?.id ?? params.colonel_id ?? -1;
      return {
        ...params,
        ...formatParamsSelectVal(
          [
            ['commission_status', -1],
            ['pay_type', -1],
            ['product', -1],
            ['team_count', -1],
            ['user_type', -1]
          ],
          params
        )
      };
    },
    getList: getColonelOrderList
  });
};
